package com.rzj.book.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

/**
 * @description:
 * @author: rzj
 * @time: 2020/6/11 21:18
 */
@RestController
@RequestMapping("waveCurveFile")
public class WaveCurveFileController extends BaseController{

    @RequestMapping("getWave")
    public String getWave(){
        File file = new File("D:\\gitCode\\book\\book-web\\src\\test\\java\\com\\rzj\\bok\\userTest\\14798_Y5-1.ZSW");
        String name = file.getName().trim();
        String parent = file.getParent()+"\\波形图"+name+"\\"+file.getName()+".data";
        File file1 = new File(parent);
        WaveCurveFile waveCurveFile = new WaveCurveFile(file1,512);
        try {
            waveCurveFile.openByRead();
            List<Short> waveDatas = waveCurveFile.read(1);
            write(JSON.toJSONString(waveDatas));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                waveCurveFile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
